var _set = require("./../../API/set.js");
const app = getApp();

Page({
  data: {
    from_address_id:0,
    to_address_id:0,
    addrInfo:{},
    userInfo:app.globalData.userInfom,
    url:app.globalData.url
  },
  onLoadFun(){
    this.setData({
      addrInfo:app.globalData.addrInfo,
      userInfo:app.globalData.userInfo,
      url:app.globalData.url
    })
    //this.getUserInfo();
  },
  onLoad() {
   
  },
  getInfo:function(){
    var self = this;
    (0, _set.getTicketInfo)().then(function(t) {
        self.setData({
          ticketinfo: t.data,
        });
    }).catch(function(t) {
      return app.Tips({
          title: t
      });
  });
  },
  onShow(){
    
  },
  toTicket:function(){
    wx.navigateTo({
      url: '/home/pages/ticket/pay',
    })
  },
  getUserInfo:function(){
    var self = this;
    (0, _set.getUserInfo)().then(function(t) {
        self.setData({
          userInfo:t.data
        })
        wx.setStorage({
          key:"userInfo",
          data:t.data
        });
        app.globalData.userInfo = t.data;
        if(t.data.shops.length>0){
            app.globalData.addrInfo ={
              address:t.data.shops[0].address,
              name:t.data.shops[0].name,
              phone:t.data.shops[0].phone,
              shop_id:t.data.shops[0].pivot.shop_id,
              realname:t.data.shops[0].realname
            }
            self.setData({
              addrInfo:app.globalData.addrInfo
            })
          }
    }).catch(function(t) {
      return app.Tips({
          title: t
      });
  });
  },
  toSubmit:function(){
    if(this.data.addrInfo.name||this.data.addrInfo!={}){
      wx.navigateTo({
        url: '/home/pages/photograph/index',
      })
    }
  },
  // getUserList:function(){
  //   var self = this;
  //   (0, _set.getUserShopList)().then(function(t) {
  //     if(t.data.length>0){
  //       app.globalData.addrInfo ={
  //         address:t.data[0].address,
  //         name:t.data[0].name,
  //         phone:t.data[0].phone,
  //         shop_id:t.data[0].pivot.shop_id,
  //         realname:t.data[0].realname
  //       }
  //       self.setData({
  //         addrInfo:app.globalData.addrInfo
  //       })
  //     }else{
  //       return app.Tips({
  //         title: '请先绑定商家！'
  //     });
  //     }
  //   }).catch(function(t) {
  //     return app.Tips({
  //         title: t
  //     });
  // });
  // },
  onPullDownRefresh: function () {
    this.getUserInfo();
    wx.stopPullDownRefresh();
  },
  toEscort(e){
    if(this.data.userInfo.is_escort == -1){
      wx.navigateTo({
        url: '/home/pages/escort_join/escort_join',
      })
    }else if(this.data.userInfo.is_escort == 0){
      return app.Tips({
          title: '您的镖师身份正在审核～'
      });
    }else if(this.data.userInfo.is_escort == 1){
      if(e.currentTarget.dataset.type ==2){
        wx.navigateTo({
          url: '/home/pages/my_task/index',
        })
      }else{
        wx.navigateTo({
          url: '/home/pages/rob_order/index',
        })
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return{
      title: "小猪速跑",
      imageUrl:app.globalData.url + '/static/img/share.png'
    };
  }
})
